package net.xdclass.product.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.xdclass.common.JsonData;
import net.xdclass.product.model.vo.ProductVO;
import net.xdclass.product.request.LockProductRequest;
import net.xdclass.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yaya
 * @since 2023-12-13
 */
@Api(tags = "商品模块")
@RestController
@RequestMapping("/api/product/v1")
public class ProductController {

    @Autowired
    private ProductService productService;

    @ApiOperation("分页查询商品列表")
    @GetMapping("/page")
    public JsonData page(@ApiParam("当前页") @RequestParam(value = "page", defaultValue = "1", required = false) int page,
                         @ApiParam("页大小") @RequestParam(value = "size", defaultValue = "10", required = false) int size){
        return productService.page(page, size);
    }

    @ApiOperation("查询商品详情")
    @GetMapping("/{id}")
    public JsonData detail(@ApiParam("商品id") @PathVariable("id") Long productId){
        ProductVO vo = productService.selectProductById(productId);
        return JsonData.buildSuccess(vo);
    }

    @ApiOperation("锁定商品库存")
    @PostMapping("/lock")
    public JsonData lockProduct(@ApiParam("商品锁定对象") @RequestBody LockProductRequest request){
        return productService.lockProduct(request);
    }

}

